package graphics;

import javax.swing.JPanel;
import javax.swing.JLabel;

import java.awt.GridBagLayout;
import java.awt.GridBagConstraints;
import java.awt.Insets;

import java.util.Observer;
import java.util.Observable;

import model.building.*;
import model.*;
import java.awt.*;

public class GStatusArea extends JPanel implements Observer {

    /** Variables de classe */
    final public static int largeur = 128;

    /** Attributs */
    private GridBagConstraints m_constraints;
    private Building           m_building;
    private BuildingFactory    m_factory;
    private JLabel             m_labelName;
    private Component          m_viewer;
    private GCity              m_gCity;

    /** Constructeurs */
    public GStatusArea(GCity gCity) {
        super(new GridBagLayout());
        m_gCity = gCity;

        m_constraints = new GridBagConstraints();
        m_constraints.gridx = 0;
        m_constraints.gridy = GridBagConstraints.RELATIVE;
        m_constraints.insets = new Insets(5,10,5,10);

        m_labelName = new JLabel("No Building Selected");
        add(m_labelName, m_constraints);
    }

    /** Accesseurs */
    public GCity getGCity() { return m_gCity; }

    /** Mutateurs */
    public void setInfo(String name, Component viewer) { 
        m_labelName.setText(name); 
        if(m_viewer != null)
            remove(m_viewer);
        m_viewer = viewer;
        if(m_viewer != null)
            add(m_viewer,m_constraints);
        repaint();
    }

    /** Methodes */
    public void update(Observable viewer, Object viewerUpdate) {
        throw new RuntimeException("ToDo");
    }

    /** Interfaces internes */
    public static interface Viewer {
        public void update(GStatusArea gStatusArea);
    }
}
